'use strict';
const db = uniCloud.database()

exports.main = async (event, context) => {
	const { action = 'client' } = event
	
	try {
		const collection = db.collection('opendb-banner')
		let query = collection
		
		// 客户端只返回启用的轮播图
		query = query.where({
			status:true
		})
		
		// 按排序号升序排列
		const res = await query.orderBy('sort', 'asc').get()
		
		return {
			code: 0,
			msg: '获取成功',
			data: res.data
		}
	} catch (e) {
		return {
			code: -1,
			msg: '获取失败',
			error: e.message
		}
	}
}